package com.guoli.sms.service.impl;

import java.sql.Connection;
import java.sql.SQLException;

import com.guoli.sms.dao.ISysuserDao;
import com.guoli.sms.dao.impl.SysuserDaoImpl;
import com.guoli.sms.service.ISysuserService;
import com.guoli.sms.util.DBTool;
import com.guoli.sms.vo.Sysuser;

public class SysuserServiceImpl implements ISysuserService {
	
	private ISysuserDao sysuserDao;
	private DBTool dbTool;
	public SysuserServiceImpl(){
		sysuserDao = new SysuserDaoImpl();
		dbTool = DBTool.newInstance();
	}
	@Override
	public Sysuser getSysuserByNP(String name, String password) {
		Connection conn = dbTool.getConnection();
		Sysuser sysuser = null;
		try {
			conn.setAutoCommit(false);
			sysuser = sysuserDao.getSysuserByNP(name, password, conn);
			conn.commit();
			conn.setAutoCommit(true);
		} catch (Exception e) {
			try {
				conn.rollback();
				conn.setAutoCommit(true);
			} catch (SQLException e1) {
				System.out.println("回滚失败...");
				e1.printStackTrace();
			}
			System.out.println("通过用户名密码查询用户失败...");
			e.printStackTrace();
		};
		
		return sysuser;
	}

}
